package dto

import (
	"time"
	"tuowei.com/app/admin/models"
	"tuowei.com/common/dto"
	common "tuowei.com/common/models"
)

type SysLiveCourseGetPageReq struct {
	dto.Pagination `search:"-"`
	Name           string `form:"name" search:"type:contains;column:name;table:sys_live_course" comment:"课程名称"`  // 课程名称
	IsShow         uint32 `form:"is_show" search:"type:exact;column:is_show;table:sys_live_course" comment:"状态"` // 状态
	StartTime      string `search:"type:gte;column:created_at;table:sys_live_course" form:"beginTime"`
	EndTime        string `search:"type:lte;column:created_at;table:sys_live_course" form:"endTime"`
}

func (m *SysLiveCourseGetPageReq) GetNeedSearch() interface{} {
	return *m
}

type SysLiveCourseInsertReq struct {
	Id        int     `json:"id"`
	Name      string  `json:"name" gorm:"varchar(20);comment:直播课程名称"`
	Label     string  `json:"label" gorm:"varchar(10);comment:直播标签"`
	Price     float64 `json:"price" gorm:"decimal(10,2);comment:直播课程价格"`
	Cover     string  `json:"cover" gorm:"varchar(255);comment:直播课程封面"`
	LiveUrl   string  `json:"live_url" gorm:"varchar(255);comment:直播链接地址"`
	StartTime string  `json:"start_time" gorm:"datetime;comment:直播开始时间"`
	EndTime   string  `json:"end_time" gorm:"datetime;comment:直播结束时间"`
	IsShow    uint32  `json:"is_show" gorm:"tinyint(1);comment:展示状态 0-不展示 1-展示"`
	common.ControlBy
}

func (s *SysLiveCourseInsertReq) Generate(model *models.SysLiveCourse) {
	model.Name = s.Name
	model.Cover = s.Cover
	model.IsShow = s.IsShow
	model.LiveUrl = s.LiveUrl
	model.StartTime, _ = time.Parse("2006-01-02 15:04:05", s.StartTime)
	model.EndTime, _ = time.Parse("2006-01-02 15:04:05", s.EndTime)
	model.Price = s.Price
	model.Label = s.Label
	model.CreateBy = s.CreateBy
	model.Creator = s.Creator
}

func (s *SysLiveCourseInsertReq) GetId() interface{} {
	return s.Id
}

type SysLiveCourseUpdateStatusReq struct {
	IsShow uint32 `json:"is_show" comment:"状态"`
	Id     int    `json:"id" comment:"课程ID" vd:"$>0; msg:'课程ID不能为空'"`
	common.ControlBy
}

func (s SysLiveCourseUpdateStatusReq) Generate(model *models.SysLiveCourse) {
	model.IsShow = s.IsShow
}

func (s SysLiveCourseUpdateStatusReq) GetId() int {
	return s.Id
}

type SysLiveCourseUpdateReq struct {
	Id        int       `json:"id"`
	Name      string    `json:"name" gorm:"varchar(20);comment:直播课程名称"`
	Label     string    `json:"label" gorm:"varchar(10);comment:直播标签"`
	Price     float64   `json:"price" gorm:"decimal(10,2);comment:直播课程价格"`
	Cover     string    `json:"cover" gorm:"varchar(255);comment:直播课程封面"`
	LiveUrl   string    `json:"live_url" gorm:"varchar(255);comment:直播链接地址"`
	StartTime string `json:"start_time" gorm:"datetime;comment:直播开始时间"`
	EndTime   string `json:"end_time" gorm:"datetime;comment:直播结束时间"`
	IsShow    uint32    `json:"is_show" gorm:"tinyint(1);comment:展示状态 0-不展示 1-展示"`
	common.ControlBy
}

func (s *SysLiveCourseUpdateReq) Generate(model *models.SysLiveCourse) {
	if s.Id != 0 {
		model.Id = s.Id
	}

	model.Name = s.Name
	model.Cover = s.Cover
	model.IsShow = s.IsShow
	model.LiveUrl = s.LiveUrl
	model.StartTime, _ = time.Parse("2006-01-02 15:04:05", s.StartTime)
	model.EndTime, _ = time.Parse("2006-01-02 15:04:05", s.EndTime)
	model.Price = s.Price
	model.Label = s.Label
	model.UpdateBy = s.UpdateBy
	model.Updater = s.Updater
}

func (s *SysLiveCourseUpdateReq) GetId() interface{} {
	return s.Id
}

type UpdateLiveCourseStatusReq struct {
	RoleId int    `json:"roleId" comment:"角色编码"` // 角色编码
	Status string `json:"status" comment:"状态"`   // 状态
	common.ControlBy
}

func (s *UpdateLiveCourseStatusReq) Generate(model *models.SysRole) {
	if s.RoleId != 0 {
		model.RoleId = s.RoleId
	}
	model.Status = s.Status
}

func (s *UpdateLiveCourseStatusReq) GetId() interface{} {
	return s.RoleId
}

type SysLiveCourseByName struct {
	RoleName string `form:"role"` // 角色编码
}

type SysLiveCourseGetReq struct {
	Id int `uri:"id"`
}

func (s *SysLiveCourseGetReq) GetId() interface{} {
	return s.Id
}

type SysLiveCourseDeleteReq struct {
	Ids []int `json:"ids"`
}

func (s *SysLiveCourseDeleteReq) GetId() interface{} {
	return s.Ids
}

type SysLiveCourseById struct {
	dto.ObjectById
	common.ControlBy
}

func (m *SysLiveCourseById) GetNeedSearch() interface{} {
	return *m
}
